// pages/my/index.js
const storeData=require("../controllers/ControllerX").controller.storeData;
const logout=require("../controllers/ControllerX").controller.logout;

const app=getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    storeData:{
      
    },
    list: [],
    surDays:'',
    itemShow:false,
    scene:"",
    nl:'',
    identityType:true,
    identityType1:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(wx.getStorageSync('diantype')==1){
      this.setData({
        list:app.globalData.list,
        nl:2
      })
    }else{
      this.setData({
        list:app.globalData.list02,
        nl:1
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getStoreData();  
    // this.judgement();
    this.getIdentityType()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // },
  jumpPage(event){
    let state=event.currentTarget.dataset.state;
    if(state=="0"){
      wx.navigateTo({
        url:"/pages/my/my_account/index"
      })
    }else if(state=="1"){
      wx.navigateTo({
        url:"/pages/my/my_card/index"
      })
    }else if(state=="2"){
      wx.navigateTo({
        url:"/pages/my/my_moneyInputHistory/index"
      })
    }else if(state=="3"){
      wx.navigateTo({
        url:"/pages/my/my_tcode/index"
      })
    }else if(state=="4"){
      wx.navigateTo({
        url:"/pages/my/my_notice/index"
      })
    }else if(state=="5"){
      wx.navigateTo({
        url:""
      })
    }else if(state=="6"){
      wx.navigateTo({
        url:"/pages/my/my_config/index"
      })
    }else if(state=="7"){
      wx.navigateTo({
        url:"/pages/my/my_serveNotice/index"
      })
    }else if(state=="8"){
      wx.navigateTo({
        url:"/pages/my/my_userFeelBack/index"
      })
    }else if(state=="9"){
      wx.navigateTo({
        url:'/pages/my/my-statistics/index'
      })
    }else if(state=="10"){
      wx.navigateTo({
        // url:"/pages/my/my_userFeelBack/index"
      })
    }else if(state=="11"){
      wx.navigateTo({
        url:"/pages/my/my_feedback/index"
      })
    }else if(state=="12"){
      wx.navigateTo({
        url:"/pages/my/my_shopDetail/index"
      })
    }else if(state=="13"){
      wx.navigateTo({
        url:"/pages/my/my_accountH5/index"
      })
    }else{
      wx.navigateTo({
        url:"/pages/my/my_shopDetail/index"
      })
    }
  },
  //获取商铺详情
  getStoreData(){
    let shopId=wx.getStorageSync('shopId');
    this.setData({
      mobile:wx.getStorageSync('mobile')
    })
    storeData({shopId:shopId}).then(res=>{
      this.setData({
        storeData:res.data
      })
      let newTime=new Date().getTime();
      let endTime=new Date(res.data.endTime.replace(/-/g,"/")).getTime();
      let surDays=Math.ceil((endTime-newTime)/1000/24/3600);
      console.log(surDays);
      this.setData({
        surDays:surDays
      })
      
    })
  },
  //tab切换
  tabChange(e){
    let index=e.detail.index;
    console.log(index);
    if(wx.getStorageSync('diantype')==1){
      if(index==0){
        wx.redirectTo({
          url: '/pages/Index/Index'
        })
      }else
      if(index==1){
        wx.redirectTo({
          url: '/pages/order/order-manage/order-manage'
        })
      }else if(index==2){
        wx.redirectTo({
          url: '/pages/my/index'
        })
      }else{
        wx.redirectTo({
          url: '/pages/my/index'
        })
      }
    }else{
      if(index==0){
        wx.redirectTo({
          url: '/pages/order/order-manage/order-manage'
        })
      }else
      if(index==1){
        wx.redirectTo({
          url: '/pages/my/index'
        })
      }
    }
  },
  //退出登录
  getLogOut(){
    logout().then(res=>{
      if(res.code==1){
        wx.showToast({
          title: res.data,
          icon: 'success',
          duration: 2000
        })
        wx.redirectTo({
          url: '/pages/login/index',
        })
        wx.removeStorageSync('token');
        wx.removeStorageSync('shopId');
      }else{
        wx.showToast({
          title: res.data,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },

  //续费跳转
  jumpInput(){
    wx.requestSubscribeMessage({
      tmplIds:["EK0YhGfRv3PZL5sY9jLOI54XskmKQ3B4aQN1x26rMZQ","fleQPapATpp6thoxCxBw1NSkonsBPrLbeow939kr4bo","Sc3aovgRuyAjgHPCxz2tKwY1udcPno6ZabDj72J5VFo"],
      success:res=>{
        console.log(res);
      },
      complete:res=>{
        wx.navigateTo({
          url: '/pages/Index/bill/bill',
        })
      }
    })
  },

  //判断是否显示公众号按钮
  judgement(){
    let scene=app.globalData.scene;
    // wx.showToast({
    //   icon:"none",
    //   title: ""+scene,
    //   duration:4000
    // })
    if(scene==1047){
      this.setData({
        itemShow:true
      })
    }else if(scene==1124){
      this.setData({
        itemShow:true
      })
    }else if(scene==1011){
      this.setData({
        itemShow:true
      })
    }else if(scene==1017){
      this.setData({
        itemShow:true
      })
    }else{
      this.setData({
        itemShow:false
      })
    }
  },

  //判断身份并隐藏相关选项
  getIdentityType(){
    let state=wx.getStorageSync('diantype');
    if(state==1){
      this.setData({
        identityType:true,
        identityType1:false,
      })
      this.judgement()
    }else{
      this.setData({
        identityType:false,
        identityType1:true,
        itemShow:false
      })
    }
  }
})